package com.gel.shortLink.admin.controller;

import com.gel.shortLink.admin.convention.result.Result;
import com.gel.shortLink.admin.convention.result.Results;
import com.gel.shortLink.admin.dto.req.ShortLinkGroupSaveReqDTO;
import com.gel.shortLink.admin.dto.req.ShortLinkGroupSortReqDTO;
import com.gel.shortLink.admin.dto.req.ShortLinkGroupUpdateReqDTO;
import com.gel.shortLink.admin.dto.resp.ShortLinkGroupRespDTO;
import com.gel.shortLink.admin.service.GroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/short-link/admin/group")
@RequiredArgsConstructor
public class GroupController {
    private final GroupService groupService;

    /*新增分组*/
    @PostMapping("/saveGroup")
    public Result<Void> saveGroup(@RequestBody ShortLinkGroupSaveReqDTO requestParam){
        groupService.saveGroup( requestParam.getName());
        return Results.success();

    }
    /*查询分组*/
    @GetMapping("/listGroup")
    public Result<List<ShortLinkGroupRespDTO>> listGroup(){
        List<ShortLinkGroupRespDTO> listGroup=groupService.listGroup();
        return Results.success(listGroup);

    }
    /*修改短链接分组*/
    @PutMapping("/updateGroup")
    public Result<Void> updateGroup(@RequestBody ShortLinkGroupUpdateReqDTO requestParam) {
        groupService.updateGroup(requestParam);
        return Results.success();
    }
    /*删除短链接分组*/
    @DeleteMapping("/deleteGroup")
    public Result<Void> deleteGroup(@RequestParam String gid) {
        groupService.deleteGroup(gid);
        return Results.success();
    }
    /*短链接分组排序*/
    @PostMapping("/sortGroup")
    public Result<Void> sortGroup(@RequestBody List<ShortLinkGroupSortReqDTO> requestParam) {
        groupService.sortGroup(requestParam);
        return Results.success();
    }
}
